import re

import requests


def request_dangdang(url):
    try:
        response = requests.get(url)
        if response.status_code == 200:
            return response.text
    except requests.RequestException:
        return None



def parse_result(html):
    pattern = re.compile("", re.S)
    items = re.findall(pattern, html)
    for item in items:
        print(item)
        # yield {
        #     'range': item[0],
        #     'image': item[1],
        #     'title': item[2],
        #     'recommend': item[3],
        #     'author': item[4],
        #     'times': item[5],
        #     'price': item[6]
        # }

def write_item_to_file(item):
    pass


def main(page):
    url = 'http://bang.dangdang.com/books/fivestars/01.00.00.00.00.00-recent30-0-0-1-' + str(page)
    html = request_dangdang(url)
    items = parse_result(html)

    for item in items:
        write_item_to_file(item)
